/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package projetmontecarlo;

import Modele.Dico;
import MultiThreaded.MonteCarloSimulationMulti;
import SingleThreaded.MonteCarloSimulation;
import Vue.Vue;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.concurrent.ExecutionException;

/**
 *
 * @author michaelrepiso
 */
public class ProjetMonteCarlo {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws FileNotFoundException, IOException, InterruptedException, ExecutionException {

        // Declaratin variables
       
        int fin = 0;

        Dico dico = new Dico();
        dico.loadData("dico.csv");

        //MonteCarlo
        MonteCarloSimulation monteCarloSingle = new MonteCarloSimulation();
        MonteCarloSimulationMulti monteCarloMulti = new MonteCarloSimulationMulti(dico);

        Vue vue = new Vue(dico);
        vue.setVisible(true);

        while (fin == 0) {
            while (vue.getStart() == 0) {
                dico.setCallPutFlag(vue.getCBCallPutFlag().getSelectedItem().toString());
                dico.setS(Double.parseDouble(vue.getCBS().getSelectedItem().toString()));
                dico.setX(Double.parseDouble(vue.getCBX().getSelectedItem().toString()));
                dico.setT(Double.parseDouble(vue.getCBT().getSelectedItem().toString()));
                dico.setR(Double.parseDouble(vue.getCBr().getSelectedItem().toString()));
                dico.setB(Double.parseDouble(vue.getCBb().getSelectedItem().toString()));
                dico.setV(Double.parseDouble(vue.getCBv().getSelectedItem().toString()));
                dico.setnSteps(Integer.parseInt(vue.getCBnSteps().getSelectedItem().toString()));
                dico.setnSimulations(Integer.parseInt(vue.getCBnSimulations().getSelectedItem().toString()));


            }

            //Get time before
            double timeBefore = System.currentTimeMillis();


            // Launch MonteCarlo
            Double result = 0.0;

            if (vue.getSingleThreaded().isSelected()) {
                result = monteCarloSingle.MonteCarloStandardOption(dico.getCallPutFlag(), dico.getS(), dico.getX(), dico.getT(),
                        dico.getR(), dico.getB(), dico.getV(), dico.getnSteps(), dico.getnSimulations(), vue);
            }

            if (vue.getMultiThreaded().isSelected()) {
                result = monteCarloMulti.MonteCarloStandardOption(dico.getCallPutFlag(), dico.getS(), dico.getX(), dico.getT(),
                        dico.getR(), dico.getB(), dico.getV(), dico.getnSteps(), dico.getnSimulations(), vue);
                
                

            }

            double timeAfter = System.currentTimeMillis(); //Get time after to compare
            double delay = timeAfter - timeBefore; // Get delay


            vue.getResult().setText(" = " + result.toString() + " euros");

            Double delays = new Double(delay);
            vue.getTime().setText(" = " + delays.toString() + " ms");

            vue.setStart(0);



        }

    }
}
